import React from 'react'
import axios from 'axios'
// import { withRouter, useHistory } from 'react-router-dom'
import withRouter from '../withRouter'
import { loadData } from '../../redux/user.redux'
import { connect } from 'react-redux'
@withRouter
@connect(
    null,
    {loadData}
)
class AuthRoute extends React.Component{
    componentDidMount() {
        const publicList = ['/login', '/register']
        // console.log(this.props)
        if(publicList.includes(this.props.location.pathname)) return
        // 获取用户信息
        axios.get('/user/info').then(res => {
            if(res.status === 200) {
                if(res.data.code === 0) {
                    // 有登录信息的
                    this.props.loadData(res.data.data)
                } else {
                    // console.log(this.props.history)
                    // console.log(this.props)
                    // let navigate = useNavigate()
                    this.props.navigate('/login')
                }
                // console.log('authroute:', res.data)
            }
        })
        // 是否登录
        // 现在的url地址，login不需要跳转
        // 用户的type身份是boss还是牛人
        // 用户是否完善信息
    }
    render(h) {
        return null
    }
}

export default AuthRoute